package com.atguigu.srb.core.controller.api;


import com.atguigu.common.results.R;
import com.atguigu.srb.core.pojo.vo.BorrowerVo;
import com.atguigu.srb.core.service.BorrowerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {
    @Autowired
    BorrowerService borrowerService;
    @ApiOperation("查询借款人借款最高额度")
    @GetMapping("auth/getBorrowerAmount")
    public R getBorrowerAmount(@RequestHeader(value = "token" , required = false)
                                           String token ){
        BigDecimal amount = borrowerService.getBorrowerAmount(token);
        return R.success().data("amount" , amount);
    }
    @ApiOperation("获取借款人审核状态")
    @GetMapping("auth/getStatus")
    public R getStatus(@RequestHeader("token")String token ){
        Integer status = borrowerService.getStatus(token);
        return R.success().data("status" , status);
    }

    @ApiOperation("保存借款人认证信息")
    @PostMapping("auth/saveBorrower")
    public R saveBorrower(@RequestBody BorrowerVo borrowerVo,
                          @RequestHeader("token")String token ){
        borrowerService.saveBorrower(borrowerVo,token);
        return R.success().message("提交成功");
    }

}

